#ifndef PGMODEL_H
#define PGMODEL_H

#include <QAbstractListModel>
#include <QQmlEngine>
#include <QQmlComponent>
#include <QString>


struct PGModelData
{
    QString         m_name;     // 名字
    QQmlComponent*  m_page;     // 功能页面
};


class PGModel : public QAbstractListModel
{
    Q_OBJECT

public:
    enum PGRoleName {
        PGNAME  = Qt::DisplayRole,  // 名字
        PGPAGE                      // 功能页面
    };

    static PGModel* instance();

    explicit PGModel(QObject *parent = nullptr);

    // Basic functionality:
    int rowCount(const QModelIndex &parent = QModelIndex()) const override;

    QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;

    virtual QHash<int,QByteArray> roleNames() const override;

    // add Data
    void remove(int index);
    void insert(const int index, PGModelData* data);
    void append(PGModelData* data);
    bool contains(QString name) const;

    PGModelData* getItem(const int index);

    int itemCount() const;

signals:
    void insertNewItem(const int index);

private:
    QList<PGModelData*> m_datas;
};

#endif // PGMODEL_H
